<?php
namespace DB;

class BaseTable
{
    public static function __callStatic($name, $args=[]) {
        echo 'there is no static method: '.$name;
    }
    
    //获取表的基本信息
    public static function getTableBasic($table)
    {
        $info = static::${$table};
        return [
            'host' => $info['host'],
            'database' => $info['database'],
            'table' => $info['table'],
            'pk' => $info['pk']
        ];
    }
    
    //获取表的基本信息
    public static function getTableName($table)
    {
        $info = static::${$table};
        return $info['table'];
    }
    
    //获取所有字段名
    public static function getFields($table)
    {
        $info = static::${$table};
        return array_keys($info['fields']);
    }
    
    //获取字段默认值
    public static function getDefaults($table)
    {
        $info = static::${$table};
        $defaults = [];
        foreach ($info['fields'] as $field => $item) {
            $defaults[$field] = $item['default'];
        }
        return $defaults;
    }
    
}
